#ifndef __OS_GUI_H__
#define __OS_GUI_H__

#include <curses.h>
#include <stdlib.h>
#include<sys/types.h>
#include<dirent.h>
#include "reg.h"
#include "watchpoint.h"
#include "redefine.h"
#include "golden_trace.h"

FILE* GUI_fp;
extern void cpu_exec(uint32_t);
extern int GUI_uio();
#define __GUI_DEBUG__ 1
#if __GUI_DEBUG__
#define log(format, ...)	\
do{	\
	fprintf(GUI_fp, "[%s,%d,%s] " format "\n", \
				__FILE__, __LINE__, __func__, ## __VA_ARGS__); \
	fflush(GUI_fp); \
}while(0)
#else
#define log(format, ...) {}
#endif

#define GUI_printf(Color, format, ...)	\
do{	\
	char* __GUI_tmp_str = malloc(128);	\
	sprintf(__GUI_tmp_str, format, ##__VA_ARGS__);	\
	add_Text(__GUI_tmp_str, Color);	\
	free(__GUI_tmp_str);	\
}while(0)

#define REG_ROW (winRow/4*3)
#define REG_COL (50)
#define MENU_ROW 3
#define MENU_COL (winCol - REG_COL)
#define TEXT_ROW (winRow - MENU_ROW)
#define TEXT_COL (MENU_COL/2)
#define ASM_ROW (TEXT_ROW)
#define ASM_COL (TEXT_COL)
#define WP_ROW (winRow - REG_ROW)
#define WP_COL (REG_COL)
#define CONSOLE_ROW 3
#define CONSOLE_COL (winCol)
#define CMD_STEP 10
#define BOX_SIDE 2
#define BOX_SPE '.'

enum{
	_continue, _quit, _single_step, _add_wp, _del_wp, _rebuild, _restart, 
	__END__};

struct{
	int y, x;
}cmdL_list[__END__];

#define NR_MENU (sizeof(menu_list) / sizeof(menu_list[0]))
#ifndef NR_WP
#define NR_WP 32
#endif
#ifndef NR_REG
#define NR_REG 32
#endif

#define WHITE_TEXT 1
#define RED_TEXT 2
#define BLUE_TEXT 3
#define YELLOW_TEXT 4
#define GREEN_TEXT 5

void init_Screen();
void init_Text();
void init_Asm();
void init_Color();
void test_Screen();
void del_Screen();
void draw_Menu();
void draw_Reg();
void draw_Text();
void draw_Asm();
void draw_Wp();
void draw_All();
void add_Text(const char*, int);
void add_Asm(const char*);
void set_cmdL(int, int, int);
void get_cmdL(int, int*, int*);
int find_cmdL(int, int);
char* GUI_getstr(WINDOW*);
int GUI_helper();
int GUI_c();
int GUI_q();
int GUI_w();
int GUI_d();
int GUI_si(int);
int GUI_rebuild();
int GUI_restart();
int GUI_console();
char* uio_handle();


#endif